package hamsterteam.hop.model;

import java.io.Serializable;
import java.util.List;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.NamedQuery;
import javax.persistence.Transient;

/**
 *
 * @author Chris
 */
@Entity
@NamedQuery(name = "Etudiant.findAll", query = "SELECT b FROM Etudiant b")
public class Etudiant implements Serializable {
    private static final long serialVersionUID = 1L;
    
    // Identifiant de l'étudiant
    @Id
    @Column(name="etuId")
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;

    /**
     * @return the nom
     */
    public String getNom() {
        return nom;
    }

    /**
     * @param nom the nom to set
     */
    public void setNom(String nom) {
        this.nom = nom;
    }

    /**
     * @return the prenom
     */
    public String getPrenom() {
        return prenom;
    }

    /**
     * @param prenom the prenom to set
     */
    public void setPrenom(String prenom) {
        this.prenom = prenom;
    }

    public boolean isSelected() {
        return selected;
    }

    public void setSelected(boolean selected) {
        this.selected = selected;
    }
    
    public static enum Option{
        NA, SICA, MIRA, SISE
    }
    
    
    private String nom;
    private String prenom;

    // Option de l'étudiant dans sa filière
    @Enumerated(EnumType.STRING)
    @Column(name="opt")
    private Option option;

    // Projets auxquels l'étudiant as participé
    @ManyToMany
    @JoinTable(
        name = "proj_etud",
        joinColumns={@JoinColumn(name="etuId", referencedColumnName = "etuId")},
        inverseJoinColumns={@JoinColumn(name="projId", referencedColumnName = "projId")})
    private List<Projet> projets;
    
    @Transient
    private boolean selected = false;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Option getOption() {
        return option;
    }

    public void setOption(Option option) {
        this.option = option;
    }

    public List<Projet> getProjets() {
        return projets;
    }

    public void setProjets(List<Projet> projets) {
        this.projets = projets;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Etudiant)) {
            return false;
        }
        Etudiant other = (Etudiant) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "hamsterteam.hop.entities.Etudiant[ id=" + id + " ]";
    }
    
}
